home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / b_proto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-04  |  7.8 KB  |  184 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*              BinkleyTerm External Protocol Handler Module                */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  27. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  28. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  29. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  30. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /*    The Authors can be reached at the following addresses:                */
  34. /*                                                                          */
  35. /*    Robert C. Hartman                      Vincent E. Perriello           */
  36. /*    Spark Software                         VEP Software                   */
  37. /*    427-3 Amherst Street                   111 Carroll Street             */
  38. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  39. /*    Nashua, NH 03061                                                      */
  40. /*                                                                          */
  41. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  42. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  43. /*                                                                          */
  44. /*    Please feel free to contact us at any time to share your comments     */
  45. /*    about our software and/or licensing policies.                         */
  46. /*                                                                          */
  47. /*--------------------------------------------------------------------------*/
  48.  
  49. #include <stdio.h>
  50. #include <signal.h>
  51. #include <ctype.h>
  52. #include <conio.h>
  53. #include <string.h>
  54. #include <process.h>
  55.  
  56. #ifdef __TURBOC__
  57. #include <alloc.h>
  58. #else
  59. #include <malloc.h>
  60. #endif
  61.  
  62. #include "com.h"
  63. #include "xfer.h"
  64. #include "zmodem.h"
  65. #include "keybd.h"
  66. #include "sbuf.h"
  67. #include "sched.h"
  68. #include "externs.h"
  69. #include "prototyp.h"       /*PLF Fri  05-05-1989  05:50:32.
  70.                              * had to truncate #include file name to
  71.                              * 8 chars. */
  72.  
  73. void do_extern (cmd, prot, name)
  74. char *cmd;                                       /* "Get" or "Send"     */
  75. char prot;                                       /* 1st letter of proto */
  76. char *name;                                      /* Name of file        */
  77. {
  78.    int i, j;
  79.    char junk[100];
  80.    char *c, *p, *m;
  81.    FILE *ctlfile;
  82.  
  83.    for (j = 0; j < 100; j++)                     /* Make sure it's all  */
  84.       junk[j] = '\0';                            /* zeroes...           */
  85.  
  86.    for (j = 0; j < 5; j++)
  87.       {
  88.       if (protos[j].first_char == prot)
  89.          break;
  90.       }
  91.    j = protos[j].entry;
  92.    c = m = protocols[j];
  93.    p = NULL;
  94.    while (*m)                                    /* Until end of string */
  95.       {
  96.       if ((*m == '\\') || (*m == ':'))           /* Look for last path  */
  97.          p = m;                                  /* Delimiter           */
  98.       m++;
  99.       }
  100.    m = &junk[0];
  101.    /* It doesn't pay to be too smart here. Dots can appear in dir names   */
  102.    while (c != p)                                /* Copy to last '\'    */
  103.       *m++ = *c++;
  104.    while (*c != '.')                             /* Then to the dot     */
  105.       *m++ = *c++;
  106.    strcat (&junk[0], ".ctl");                    /* Then add extension  */
  107.  
  108.    /*
  109.     * At this point we have the Control File name in (junk), Now let's open
  110.     * the file and put our good stuff in there. 
  111.     */
  112.  
  113.    unlink (junk);                                /* Delete old copies   */
  114.    if ((ctlfile = fopen (junk, "a")) == NULL)    /* Try to open it      */
  115.       {
  116.       status_line ("!Couldn't open CTL file: %s", junk);
  117.       return;
  118.       }
  119.  
  120.    errno = 0;
  121.    fprintf (ctlfile, "Port %d\n", (port_ptr + 1));      /* Port n              */
  122.    if (errno)
  123.       goto err;
  124.    if (lock_baud)
  125.       i = max_baud;
  126.    else i = cur_baud;
  127.  
  128.    fprintf (ctlfile, "Modem %x %x %x %x %x\n",   /* All modem params    */
  129.          (port_ptr + 1), i, handshake_mask, carrier_mask, cur_baud);
  130.    if (errno)
  131.       goto err;
  132.    fprintf (ctlfile, "Baud %u\n", cur_baud);     /* Baud Rate           */
  133.    if (errno)
  134.       goto err;
  135.    fprintf (ctlfile, "%s %s\n", cmd, name);      /* Actual command      */
  136.    if (errno)
  137.       {
  138. err:
  139.       status_line ("!Error writing line to CTL file");
  140.       fclose (ctlfile);
  141.       errno = 0;
  142.       return;
  143.       }
  144.    fclose (ctlfile);
  145.    if (errno)
  146.       {
  147.       status_line ("!Error closing CTL file: %s", junk);
  148.       errno = 0;
  149.       return;
  150.       }
  151.    /* The file is now written. Turn off everything. */
  152.  
  153.    if (!share)
  154.       MDM_DISABLE ();                            /* Turn off FOSSIL     */
  155.  
  156.    if (status_log != NULL)
  157.       fclose (status_log);                       /* Close status log    */
  158.  
  159.    /* We're all set. Build the command and execute it. */
  160.  
  161.    c = protocols[j];
  162.    sprintf (e_input, "%s %s -p%d -b%u %s", c, c, (port_ptr + 1), cur_baud, junk);
  163.    b_spawn (e_input);                            /* Execute command     */
  164.  
  165.    /* Back from external protocol. Turn it all back on. */
  166.  
  167.    if (Cominit (port_ptr) != 0x1954)             /* FOSSIL back on      */
  168.       {
  169.       cprintf ("\r\nDarn!  The FOSSIL seems to have gone away!  Exiting\r\n");
  170.       exit (1);
  171.       }
  172.  
  173.    if (status_log != NULL)                       /* Reopen status log   */
  174.       {
  175.       if ((status_log = fopen (log_name, "at")) == NULL)
  176.          {
  177.          cprintf ("\r\nCannot re-open logfile\r\n");
  178.          }
  179.       }
  180.  
  181.    MDM_ENABLE (btypes[baud].rate);               /* Reset baud rate     */
  182.    XON_ENABLE ();                                /* and reenable XON/OF */
  183. }
  184.